package cn.com.nes.site.action.crm;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.crm.CustomerService;

@Controller("customer")
@RequestMapping("/customer")
public class CustomerAction  {
	@Resource
    private CustomerService service;
	
	//获取客户列表
    @RequestMapping(method = RequestMethod.POST, value = "/getCustomerList")
    public @ResponseBody
    PageData getCustomerList(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCustomerList(req) ;
        return res;
    }
    
  //客户新建保存
    @RequestMapping(method = RequestMethod.POST, value = "saveCustomer")
    public @ResponseBody
    PageData saveCustomer(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveCustomer(req) ;
        return res;
    }
    
  //客户明细查询
    @RequestMapping(method = RequestMethod.POST, value = "/getCustomerDetail")
    public @ResponseBody
    PageData getCustomerDetail(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCustomerDetail(req) ;
        return res;
    }
    
  //客户明细查询_联系人保存
    @RequestMapping(method = RequestMethod.POST, value = "/addCustomerStaff")
    public @ResponseBody
    PageData saveCustomerStaff(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveCustomerStaff(req) ;
        return res;
    }
    
  //客户明细查询_联系人删除
    @RequestMapping(method = RequestMethod.POST, value = "/delCustomerStaff")
    public @ResponseBody
    PageData delCustomerStaff(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delCustomerStaff(req) ;
        return res;
    }
    
    //客户明细查询_跟进记录添加
    @RequestMapping(method = RequestMethod.POST, value = "/addCustomerClaim")
    public @ResponseBody
    PageData saveCustomerClaim(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveCustomerClaim(req) ;
        return res;
    }
    
  //客户明细查询_跟进记录删除
    @RequestMapping(method = RequestMethod.POST, value = "/delCustomerClaim")
    public @ResponseBody
    PageData delCustomerClaim(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delCustomerClaim(req) ;
        return res;
    }
    
  //客户明细查询_文件添加
    @RequestMapping(method = RequestMethod.POST, value = "/addCustomerFile")
    public @ResponseBody
    PageData saveCustomerFile(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveCustomerFile(req) ;
        return res;
    }
    
    //客户明细查询_文件删除
    @RequestMapping(method = RequestMethod.POST, value = "/delCustomerFile")
    public @ResponseBody
    PageData delCustomerFile(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delCustomerFile(req) ;
        return res;
    }
    
  //删除客户
    @RequestMapping(method = RequestMethod.POST, value = "/delCustomer")
    public @ResponseBody  PageData delCustomer(HttpServletRequest request,
                                                  HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delCustomer(req) ;
        return res;
    }

  //获取客户动态
    @RequestMapping(method = RequestMethod.POST, value = "/getDynamic")
    public @ResponseBody  PageData getCustomerDynamic(HttpServletRequest request,
                                                  HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCustomerDynamic(req) ;
        return res;
    }
    
  //获取客户联系人列表
    @RequestMapping(method = RequestMethod.POST, value = "/getCustomerStaff")
    public @ResponseBody  PageData getCustomerStaff(HttpServletRequest request,
                                                  HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCustomerStaff(req) ;
        return res;
    }
}
